package org.layuiframework.generator.engine;

import com.baomidou.mybatisplus.generator.config.rules.FileType;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.io.File;
import java.util.HashMap;

@Getter
@AllArgsConstructor
public enum StereotypePath {

    ADVICE_EXCEPTION("ControllerExceptionAdvice", "/templates/stereotype/advice/exception.java", "advice" + File.separator),
    ANNOTATION_ADVICE("NotControllerResponseAdvice", "/templates/stereotype/annotation/advice.java", "annotation" + File.separator),
    ANNOTATION_EXCEL("ImportFromFile", "/templates/stereotype/annotation/excel.java", "annotation" + File.separator),
    AOP_EXCEL("ImportFileAopByEasyExcel", "/templates/stereotype/aop/excel.java", "aop" + File.separator),
    CONFIG_SPRINGMVC("SpringMvcConfig", "/templates/stereotype/config/springmvc.java", "config" + File.separator),
    CONFIG_ELASTICSEARCH("ElasticsearchConfiguration", "/templates/stereotype/elasticsearch/config.java", "elasticsearch" + File.separator),
    HANDLER_ELASTICSEARCH("ElasticsearchHandler", "/templates/stereotype/elasticsearch/handler.java", "elasticsearch" + File.separator),
    HANDLERS_ELASTICSEARCH("ElasticsearchHandlers", "/templates/stereotype/elasticsearch/handlers.java", "elasticsearch" + File.separator),
    RECORD_ELASTICSEARCH("ElasticsearchRecord", "/templates/stereotype/elasticsearch/record.java", "elasticsearch" + File.separator),
    VO_ELASTICSEARCH("ElasticsearchVo", "/templates/stereotype/elasticsearch/vo.java", "elasticsearch" + File.separator),
    EXCEPTION_API("APIException", "/templates/stereotype/exception/api.java", "exception" + File.separator),
    EXCEPTION_UTIL("ThrowUtils", "/templates/stereotype/exception/util.java", "exception" + File.separator),
    HANDLER_METAOBJECT("MyMetaObjectHandler", "/templates/stereotype/handler/metaobject.java", "handler" + File.separator),
    SECURITY_AUTHENTICATION_SUCCESS("AuthenticationSuccess", "/templates/stereotype/security/authentication/success.java", "security" + File.separator + "authentication" + File.separator),
    SECURITY_AUTHENTICATION_FAILURE("AuthenticationFailure", "/templates/stereotype/security/authentication/failure.java", "security" + File.separator + "authentication" + File.separator),
    SECURITY_BEAN_KEYPAIR("AbstractKeyPair", "/templates/stereotype/security/bean/keypair.java", "security" + File.separator + "bean" + File.separator),
    SECURITY_BEAN_LOGINUSER("LoginUser", "/templates/stereotype/security/bean/loginuser.java", "security" + File.separator + "bean" + File.separator),
    SECURITY_BEAN_USER("AbstractUser", "/templates/stereotype/security/bean/user.java", "security" + File.separator + "bean" + File.separator),
    SECURITY_FILTER_JWT("JwtAuthorizationFilter", "/templates/stereotype/security/filter/jwt.java", "security" + File.separator + "filter" + File.separator),
    SECURITY_FILTER_VERIFY("VerifyCodeFilter", "/templates/stereotype/security/filter/verify.java", "security" + File.separator + "filter" + File.separator),
    SECURITY_HANDLER_ACCESS("RestfulAccessDeniedHandler", "/templates/stereotype/security/handler/access.java", "security" + File.separator + "handler" + File.separator),
    SECURITY_HANDLER_AJAX("AjaxAuthenticationEntryPoint", "/templates/stereotype/security/handler/ajax.java", "security" + File.separator + "handler" + File.separator),
    SECURITY_HANDLER_LOGOUT("LogoutSuccess", "/templates/stereotype/security/handler/logout.java", "security" + File.separator + "handler" + File.separator),
    SECURITY_IMPL_CACHE("CacheServiceImpl", "/templates/stereotype/security/impl/cache.java", "security" + File.separator + "impl" + File.separator),
    SECURITY_IMPL_LOGIN("LoginAttemptService", "/templates/stereotype/security/impl/login.java", "security" + File.separator + "impl" + File.separator),
    SECURITY_IMPL_PROVIDER("UserAuthenticationProvider", "/templates/stereotype/security/impl/provider.java", "security" + File.separator + "impl" + File.separator),
    SECURITY_IMPL_USERGETTER("AbstractUserGetter", "/templates/stereotype/security/impl/usergetter.java", "security" + File.separator + "impl" + File.separator),
    SECURITY_IMPL_VERIFYCODE("VerifyCode", "/templates/stereotype/security/impl/verifycode.java", "security" + File.separator + "impl" + File.separator),
    UTIL_JWT("JwtUtil", "/templates/stereotype/util/jwt.java", "util" + File.separator),
    UTIL_RSA("RSAUtils", "/templates/stereotype/util/rsa.java", "util" + File.separator),
    UTIL_SPRING("SpringContextUtil", "/templates/stereotype/util/spring.java", "util" + File.separator),
    UTIL_VALID("ValidGroup", "/templates/stereotype/util/valid.java", "util" + File.separator),
    VO_APPCODE("AppCode", "/templates/stereotype/vo/appcode.java", "vo" + File.separator),
    VO_LAYUI("LayuiTableVo", "/templates/stereotype/vo/layui.java", "vo" + File.separator),
    VO_PAGEINFO("PageInfo", "/templates/stereotype/vo/pageinfo.java", "vo" + File.separator),
    VO_RESULTCODE("ResultCode", "/templates/stereotype/vo/resultcode.java", "vo" + File.separator),
    VO_RESULTVO("ResultVo", "/templates/stereotype/vo/resultvo.java", "vo" + File.separator),
    VO_STATUSCODE("StatusCode", "/templates/stereotype/vo/statuscode.java", "vo" + File.separator),
    ;

    private String name;
    private String path;
    private String route;

    public static void generator(String path, HashMap objectMap, FreemarkerTemplateEngine engine){
        StereotypePath [] enums = values();
        for (StereotypePath e: enums) {
            if (engine.isCreate(FileType.OTHER, path + File.separator + e.getRoute() + File.separator + e.getName() + ".java")) {
                try {
                    engine.writerFile(objectMap, e.getPath() + ".ftl", path + File.separator + e.getRoute() + File.separator + e.getName() + ".java");
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
    }

}
